////////////////////////////////////////////////////////////
// Workfile : AddressManager.cpp
// Author : Andreas Lehner
// Date : 5.11.2012
// Description : manages addresses and persons; reads files,
// links addresses with persons and writes files,
// implements interfaces IWrite and IRead INTERFACE
// Remarks : 0
// Revision : 1
////////////////////////////////////////////////////////////
#ifndef ADDRESSMANAGER_H
#define ADDRESSMANAGER_H

#include <string>
#include <map>
#include <list>
#include <vector>
#include "Object.h"
#include "Person.h"
#include "Address.h"
#include "Reader.h"
#include "Writer.h"
#include "IRead.h"
#include "IWrite.h"

//some typedefs of iterators for map
typedef IWrite::TAddressNamesMap::iterator AddressMapIter;
typedef IWrite::TAddressNamesMap::const_iterator AddressMapConstIter;

class AddressManager : public Object, public IWrite, public IRead {
public:
	//read addresses or persons from file (txt)
	void ReadFile(std::string const& filename, Reader *read);
	//link persons with addresses
	void LinkAddresses();
	//write addresses with persons to file (html or ascii)
	void WriteAddresses(std::string const& filename, Writer *write);

	// Implement Interface IRead
	void addAddress(Address const& adr);
	void addPerson(Person const& pers);

	// Implement Interface IWrite
	TAddressNamesMap const* getAddressesWithNames() const;

	//get number of addresses
	size_t getNumberOfAddresses() const;

private:
	//some typedefs of iterators
	typedef std::list<Person>::iterator TPersonsIter;
	typedef std::vector<Address>::iterator TAddressesIter;
	//list of persons
	std::list<Person> mPersons;
	//vector of addresses
	std::vector<Address> mAddresses;
	//map for linking names with addresses
	//holds Address* and list<Person*>
	TAddressNamesMap mLink;
};

#endif